﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Diagnostics;
using log4net;
using System.IO;

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
namespace MaxLeaf.Common
{
    public class MaxLeafException : Exception
    {
        public MaxLeafException(string strMsg):base(strMsg)
        {
            
        }
    }
       
    public class LogManager
    {
        const string LOGNAME = "MaxLeaf";
        private static bool _Inited { get; set; }
        private static void Init()
        {
            log4net.Config.XmlConfigurator.Configure(new FileInfo(BaseFunctions.GetBinPath()+"log4net.config"));
            _Inited = true;
        }
        public static void Error(Exception ex)
        {
            if (!_Inited) Init();
            ILog log = log4net.LogManager.GetLogger(LOGNAME);
            //记录错误日志   
            if (ex is MaxLeafException)
            {
                log.Fatal(ex.Message);
            }
            
                log.Error("error", ex);
             

        }
        public static void Info(string strMsg)
        {
            if (!_Inited) Init();
            ILog log = log4net.LogManager.GetLogger(LOGNAME);
            //记录一般信息  
            log.Info(strMsg );

        }

        public static void Debug(string strMsg)
        {
            if (!_Inited) Init();
            ILog log = log4net.LogManager.GetLogger(LOGNAME);
            //记录调试信息 
            log.Debug(strMsg);

        }

        public static void Warn(string strMsg)
        {
            if (!_Inited) Init();
            ILog log = log4net.LogManager.GetLogger(LOGNAME);
            //记录警告信息   
            log.Warn(strMsg);

        }
    }
}